<?php

// [ 检查前置操作 ]

namespace app\api\behavior;
use app\api\lib\Response;
use think\facade\Cache;
use think\facade\Session;

class CheckPre
{
	private $_req = null;
	
    public function run($arg)
    {
    	$this->_req = $arg[0];
        $class      = $arg[1];
        
        $pre = $class->_pre;
        if ( !empty($pre) ) {
            foreach ($pre as $val) $this->{$val}();
        }
    }

    // -------------------------------------------------------------------------------------------------

    // 检查是否会员登录
    private function member()
    {
        Session::has('member') || Response::send(403,'未授权[会员]');
        
        $deviceApi = $this->_req->param('device/s','','trim');
        $mobile    = Session::get('member.mobile');
    	$deviceCac = Cache::get('device_' . $mobile);
    	if (!$deviceCac) Response::send(403,'未登录[会员][1]'); 
    	if ($deviceApi != $deviceCac) Response::send(403,'未登录[会员][2]');
    }
}
